package com.jnks.utils;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jnks.constant.BaseConstants;


/**
 * 分页工具
 *
 * @author Ryo
 * @since 2024-04-12
 */
public class Condition {

    /**
     * 转化成mybatis plus中的Page
     *
     * @param commonDto
     * @return
     */
    public static <T> IPage<T> getPage(CommonDto commonDto) {
        if (commonDto.getPageSize() > BaseConstants.PAGE_MAX_SIZE) {
            commonDto.setPageSize(BaseConstants.PAGE_MAX_SIZE);
        }
        return new Page<>(commonDto.getPageNum(), commonDto.getPageSize());
    }

    /**
     * 转化成mybatis plus中的Page
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    public static <T> IPage<T> getPage(Integer pageNum, Integer pageSize) {
        if (pageSize > BaseConstants.PAGE_MAX_SIZE) {
            pageSize = BaseConstants.PAGE_MAX_SIZE;
        }
        return new Page<>(pageNum, pageSize);
    }

    /**
     * 获取mybatis plus中的QueryWrapper
     *
     * @param entity
     * @param <T>
     * @return
     */
    public static <T> QueryWrapper<T> getQueryWrapper(T entity) {
        return new QueryWrapper<>(entity);
    }

    /**
     * 获取mybatis plus中的QueryWrapper
     *
     * @return
     */
    public static <T> QueryWrapper<T> getQueryWrapper() {
        return new QueryWrapper<>();
    }

}
